package com.wry.consumer;

import com.wry.api.SpikeService;
import com.wry.entity.Goods;
import com.wry.entity.Order;
import com.wry.enums.OrderStatusEnum;
import com.wry.service.GoodsService;
import com.wry.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * <h1>  <h1>
 *
 * @author 魏如元
 * @since 2022/7/18
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "ORDER_PAY_TOPIC",consumerGroup = "group-pay")
public class PayConsumer implements RocketMQListener<String> {

    @Resource
    private OrderService orderService;

    @Override
    public void onMessage(String msg) {
        final Order order = orderService.lambdaQuery()
                .eq(Order::getOrderId, String.valueOf(msg))
                .one();
        order.setStatus(OrderStatusEnum.SUCCESS.name());
        orderService.updateById(order);
        log.info("++++++++++【{}】:支付完成+++++++++++",msg);
    }
}
